<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>分享读书单-夜读书</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="夜读书">
    <meta name="description" content="夜读书中文网">
    <meta name="keywords" content="读书,阅读,小说,文学">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{{ asset('/bootstrap-3.3.5-dist/css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/yds.css') }}">
    <link rel="stylesheet" href="{{ asset('/style/css/ucenter.css') }}">
    <script src="{{ asset('/scripts/jquery/jquery-1.11.3.min.js') }}"></script>
    <script src="{{ asset('/bootstrap-3.3.5-dist/js/bootstrap.min.js') }}"></script>
    {{-- umeditor --}}
    <script type="text/javascript" charset="utf-8" src="{{ asset('/editor/uaddbk_ueditor1_4_3_1/ueditor.config.js') }}"></script>
    <script type="text/javascript" charset="utf-8" src="{{ asset('/editor/uaddbk_ueditor1_4_3_1/ueditor.all.js') }}"> </script>
    <script type="text/javascript" charset="utf-8" src="{{ asset('/editor/uaddbk_ueditor1_4_3_1/lang/zh-cn/zh-cn.js') }}"></script>
    {{-- umeditor end--}}
</head>
<body>
@include('books.partials.navtop')
@include('books.partials.nav')
<div id="yds_screen">
<div id="yds_content" class="clearfix">
  <div class="article">
   <h1>分享读书单</h1>
   <div style="border-bottom: 1px solid #eeeeee;"></div>
    <form name="form" class="form-horizontal" role="form" method="post" action="saveshudan" enctype="multipart/form-data">
     <input type="hidden" name="_token" value="{{ csrf_token() }}" />
    <div class="">
      <label for="biaoti" class="control-label">标题*：</label>      
        <input type="text" class="form-control" name="biaoti" id="biaoti" value="">      
    </div>
    <div class="">
      <label for="jieshao" class="control-label">介绍*:</label>
        <script type="text/plain" id="jieshao" name="jieshao" style="width:100%;height:150px;"></script>
    </div>
    <label>给这个读书单添加图书</label>
    <span class="" style="display:block;margin-bottom:10px;">请输入图书在夜读书的页面地址,如 http://www.yedushu.com/info/12049 <a href="http://www.yedushu.com" target="_blank">去夜读书搜索</a></span>
    <div><ul style="margin:0; padding:0; list-style:none;" id="shudan"></ul><a href="#">+增加输入框</a></div>
        <div>
        <button type="button" id="okbutton" class="btn btn-success" style="float:right">添加书单</button>
      </div>
    <script type="text/javascript">
    //实例化编辑器
    var ueneirongjianjie = UE.getEditor('jieshao');
    </script>
    </form>
  </div>
  <div class="aside">
  <div class="indent">
    <span class="">提示...</span>
    <p>书单如果过长的话，选择其中最好的添加，一次不要超过20本书。</p>
    <p>如果书单超过20本，请先添加20本后，选择编辑书单可继续增加。</p>
  </div>
  </div>
</div>
</div>
<script type="text/javascript">
$(function(){
  $("#shudan").easyinsert({                
                toplimit: 20,
        });  
});
/**
 * EasyInsert 4.0
 *
 * @Depend    jQuery 1.4+
**/
;(function($){
  $.fn.extend({
    "easyinsert": function(o){
      o = $.extend({
        //触发器
        clicker: null,//根据class（或id）选择，默认.next()获取
        //父标签
        wrap: "li",
        //name: "i-text",
        name: "shudanlist[]",
        type: "text",
        value: "",
        maxlength: 100,
        className: "i-text",
        style: "width:450px; margin-bottom:9px",
        id: "shudanlist",
        //新增上限值
        toplimit: 0,//0表示不限制
        //初始化值，二维数组
        initValue: null//用于修改某资料时显示已有的数据
      }, o || {});
      var oo = {
        remove: "<a href=\"#nogo\" class=\"remove\" style=\"padding-left:9px\">移除</a>",
        error1: "参数配置错误，数组的长度不一致，请检查。",
        error2: "参数配置错误，每组初始化值都必须是数组，请检查。"
      }
      //容器
      var $container = $(this);
      var allowed = true;
      //把属性拼成数组（这步不知道是否可以优化？）
      var arrCfg = new Array(o.name, o.type, o.value, o.maxlength, o.className, o.style, o.id);
      //arr ==> [name, type, value, maxlength, className]
      var arr = new Array();
      $.each(arrCfg, function(i, n){
        if ( $.isArray(n) ) {
          arr[i] = n;
        } else {
          arr[i] = new Array();
          if ( i === 0 ) {
            arr[0].push(n);
          }else{
            //补全各属性数组（根据name数组长度）
            $.each(arr[0], function() {
              arr[i].push(n);
            });
          }
        }
        //判断各属性数组的长度是否一致
        if ( arr[i].length !== arr[0].length ) {
          allowed = false;
          $container.text(oo.error1);
        }
      });
      if ( allowed ) {
        //获取触发器
        var $Clicker = !o.clicker ? $container.next() : $(o.clicker);
        $Clicker.bind("click", function() {
          //未添加前的组数
          var len = $container.children(o.wrap).length;
          //定义一个变量，判断是否已经达到上限
          var isMax = o.toplimit === 0 ? false : (len < o.toplimit ? false : true);
          if ( !isMax ) {//没有达到上限才允许添加
            var $Item = $("<"+ o.wrap +">").appendTo( $container );
            $.each(arr[0], function(i) {
              switch ( arr[1][i] ) {
                case "select"://下拉框
                  var option = "";
                  $.each(arr[2][i], function(i, n) {
                    option += "<option value='"+ n +"'>"+ i +"</option>";
                  });
                  $("<select>", {
                    name: arr[0][i],
                    className: arr[4][i]
                  }).append( option ).appendTo( $Item );
                  break;
                case "custom"://自定义内容，支持html
                  $Item.append( arr[2][i] );
                  break;
                default://默认是input
                  $("<input>", {//jQuery1.4新增方法
                    name: arr[0][i],
                    type: arr[1][i],
                    value: arr[2][i],
                    maxlength: arr[3][i],
                    className: arr[4][i],
                    style: arr[5][i],
                    id: arr[6][i],
                  }).appendTo( $Item );
              }
            });
            $Item = $container.children(o.wrap);
            //新组数
            len = $Item.length;
            if ( len > 1 ) {
              $Item.last().append(oo.remove);
              if ( len === 2 ) {//超过一组时，为第一组添加“移除”按钮
                $Item.first().append(oo.remove);
              }
            }
            $Item.find(".remove").click(function(){
              //移除本组
              $(this).parent().remove();
              //统计剩下的组数
              len = $container.children(o.wrap).length;
              if ( len === 1 ) {//只剩一个的时候，把“移除”按钮干掉
                $container.find(".remove").remove();
              }
              //取消“移除”按钮的默认动作
              return false;
            });
          }
          //取消触发器的默认动作
          return false;
        });
        //初始化
        if ( $.isArray(o.initValue) ) {//判断初始值是否是数组（必需的）
          $.each(o.initValue, function(i, n) {
            if ( !$.isArray(n) ) {
              $container.empty().text(oo.error2);
              return false;
            }else{
              if ( n.length !== arr[0].length ) {
                $container.empty().text(oo.error1);
                return false;
              }
            }
            var arrValue = new Array();
            //初始值替换默认值
            $.each(n, function(j, m) {
              arrValue[j] = arr[2][j]
              arr[2][j] = m;
            });
            $Clicker.click();
            //默认值替换初始值
            $.each(arrValue, function(j, m) {
              arr[2][j] = m;
            });
            //上面这种[移形换位法]不知道效率怎么样，我想不出别的更好的方法
          });
        }else{
          $Clicker.click();
        }
      }
    }
  });
})(jQuery);
</script>

<script>
$(document).ready(function(){
    $("#okbutton").click(function(){
        if($.trim($("#biaoti").val())=="")
        {
            alert("请输入标题。");
            $("#biaoti").focus();
        }
        else if(!UE.getEditor('jieshao').hasContents())
        {
            alert("请输入介绍。");
            UE.getEditor('jieshao').focus();
        }
        else if($.trim($("#shudanlist").val())=="")
        {
            alert("请输入要添加的书单。");
            $("#shudanlist").focus();
        }
        else
        {
            form.submit();
        }
    });
});
</script>

@include('books.partials.footer')
</body>
</html>
